<template>
  <div class="headcontainer" :loading="loading">
    <slot name="left_title">
      <div class="left">
        <p />
        <span>滴咚个游 ·</span>
        <span>旅行社入驻</span>
      </div>
    </slot>
    <slot name="right_title">
      <div class="phone_box" v-if="!showphone">
        {{ phone }}
        <span @click="logout">退出</span>
      </div>
    </slot>
  </div>
</template>

<script>
import { mapActions } from "vuex";

export default {
  data() {
    return {
      phone: "",
      showphone: false,
    };
  },
  props: ["loading"],
  computed: {
    ...mapActions(["logOut"]),
  },
  beforeMount() {
    if (window.localStorage.getItem("userphone")) {
      let phones = window.localStorage.getItem("userphone");
      this.phone = phones.substr(0, 3) + "****" + phones.substr(7);
      // console.log(this.phone);
    } else {
      this.showphone = true;
    }
  },
  methods: {
    // this.setphone(window.localStorage.getItem("userphone"));
    logout() {
      this.$emit("loadingChan", true);
      setTimeout(() => {
        this.$store.dispatch("logOut");
        this.$router.replace({ name: "Login" });
        window.localStorage.removeItem("token");
        window.localStorage.removeItem("userphone");
      }, 400);
    },
  },
};
</script>

<style lang='less'>
div.phone_box {
  user-select: none;
  height: 5vh;
  line-height: 5vh;
  line-height: 5vh;
  position: absolute;
  right: 20px;
  span {
    margin-left: 8px;
    padding: 0 5px;
    display: inline-block;
    color: #07c160;
    cursor: pointer;
  }
}
div.headcontainer {
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
  user-select: none;
  position: absolute;
  display: flex;
  align-items: center;
  left: 0;
  top: 0;
  width: 100%;
  height: 5vh;
  background-color: #fff;
  .right {
    height: 5vh;
    line-height: 5vh;
    width: 100px;
    float: right;
  }
}

div.left {
  & > * {
    float: left;
  }
  span:nth-child(2) {
    padding-left: 10px;
    font-size: 19px;
    font-weight: 600;
  }
  span:last-child {
    font-size: 19px;
    text-indent: 8px;
  }
  p:first-child {
    margin-left: 20px;
    width: 30px;
    height: 30px;
    background: #cccccc;
    opacity: 1;
    border-radius: 10px;
  }
}
</style>